package se.webbzon.oschi01.resourceset;

import java.util.Collection;

import se.webbzon.oschi01.friendly.Friendly;

public class ResourceSet<R> {
	
	// An array of all resources in this set
	private final R[] resources;
	
	// The hash code of this resource set
	private final int hashCode;
		
	/*============================================================
	Constructors
	============================================================*/
		
	/** Creates a new generic ResourceSet from a collection of resources. **/
	@SuppressWarnings("unchecked")
	@Friendly ResourceSet(Collection<R> resources, int hashCode) {
		this.resources = (R[]) resources.toArray();
		this.hashCode = hashCode;
	}
		
	/** Creates a new generic ResourceSet from an array of resources. **/
	@Friendly ResourceSet(R[] resources, int hashCode) {
		this.resources = resources.clone();
		this.hashCode = hashCode;
	}
		
	/*============================================================
	Public Methods
	============================================================*/
		
	/** Returns the (n+1):th resource from the resource set. **/
	public R get(int n) {
		return resources[n];
	}
		
	/** Returns the number of resources in this resource set. **/
	public int size() {
		return resources.length;
	}

	@Override public int hashCode() {
		return hashCode;
	}

}
